﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefPackageRecord" :model="statePackageRecord.vmModel" label-width="100px">
      <el-row>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_PackageId_FormItem" prop="Entity.PackageId" :label="$t('message.autotrans._Model_PackageRecord_Package')">
            <el-select v-model="statePackageRecord.vmModel.Entity.PackageId" clearable>
               <el-option v-for="item in statePackageRecord.AllPackages" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_WoId_FormItem" prop="Entity.WoId" :label="$t('message.autotrans._Model_PackageRecord_WoId')">
            <el-input v-model="statePackageRecord.vmModel.Entity.WoId" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_WoCode_FormItem" prop="Entity.WoCode" :label="$t('message.autotrans._Model_PackageRecord_WoCode')">
            <el-input v-model="statePackageRecord.vmModel.Entity.WoCode" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_ProductId_FormItem" prop="Entity.ProductId" :label="$t('message.autotrans._Model_PackageRecord_ProductId')">
            <el-input v-model="statePackageRecord.vmModel.Entity.ProductId" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_ProductName_FormItem" prop="Entity.ProductName" :label="$t('message.autotrans._Model_PackageRecord_ProductName')">
            <el-input v-model="statePackageRecord.vmModel.Entity.ProductName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Sn_FormItem" prop="Entity.Sn" :label="$t('message.autotrans._Model_PackageRecord_Sn')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_PackageRecord_Sn')}), trigger: 'blur' }]" >
            <el-input v-model="statePackageRecord.vmModel.Entity.Sn" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_PartSn_FormItem" prop="Entity.PartSn" :label="$t('message.autotrans._Model_PackageRecord_PartSn')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_PackageRecord_PartSn')}), trigger: 'blur' }]" >
            <el-input v-model="statePackageRecord.vmModel.Entity.PartSn" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_StartTime_FormItem" prop="Entity.StartTime" :label="$t('message.autotrans._Model_PackageRecord_StartTime')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_PackageRecord_StartTime')}), trigger: 'blur' }]" >
            <el-date-picker v-model="statePackageRecord.vmModel.Entity.StartTime" type='date' clearable></el-date-picker>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Remark_FormItem" prop="Entity.Remark" :label="$t('message.autotrans._Model_PackageRecord_Remark')">
            <el-input v-model="statePackageRecord.vmModel.Entity.Remark" clearable></el-input>
        </el-form-item>

        </el-col>
      </el-row>

      <div style="text-align:right;">
        <WtmButton @click="onSubmitPackageRecord"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

        <WtmButton @click="onClosePackageRecord"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PagePackageManagementPackageRecordEdit;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { packagerecordApi } from '/@/api/packagemanagement/packagerecord';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefPackageRecord = ref();
const statePackageRecord = reactive({
    vmModel: {
	  Entity:{
        PackageId: null,
        WoId: null,
        WoCode: '',
        ProductId: null,
        ProductName: '',
        Sn: '',
        PartSn: '',
        StartTime: undefined,
        Remark: '',
        ID:null,
      },

	},
    
    AllPackages: [] as any[],
});

// 取消
const onClosePackageRecord = () => {
    closeDialog();
};

// 提交
const onSubmitPackageRecord = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefPackageRecord.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            packagerecordApi().edit(statePackageRecord.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};

// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/PackageManagement/PackageRecord/GetPackageBanks',[],false).then(x=>{statePackageRecord.AllPackages = x});
    if (ci.attrs["wtmdata"]) {
		statePackageRecord.vmModel.Entity.ID = ci.attrs["wtmdata"].ID;
	}
	else if (useRouter().currentRoute.value.query.id) {
		statePackageRecord.vmModel.Entity.ID = useRouter().currentRoute.value.query.id as any;
	}
	packagerecordApi().get(statePackageRecord.vmModel.Entity.ID ?? "").then((data: any) => other.setValue(statePackageRecord.vmModel, data));
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

